class Solution
{
public:
    int jump(vector<int> &nums)
    {
        int n = nums.size();
        int covered = 0;
        int step = 0;
        int i = 0;
        while (covered < n - 1)
        {
            int nextCover = covered;
            while (i <= covered)
            {
                nextCover = max(nextCover, i + nums[i]);
                ++i;
            }
            covered = nextCover;
            ++step;
        }
        return step;
    }
};